package 笔试;

public class 二分 {

    public static void main(String[] args) {
//        System.out.println(sea(new int[]{1,2,3}, 2));
        Integer a1=new Integer(50);
        Integer a2= 555;
        Integer a22= 555;
        Integer a3= Integer.valueOf(555);
        Integer a4=20;
        Integer a5=30;
        Integer a6=new Integer(50);
        Integer a7=new Integer(50);

        System.out.println(a2==a3);


    }
    public static int[] searchRange(int[] nums, int target) {
        if(nums.length==0) return new int[]{-1,-1};
        int min=sea(nums,target);
        int max=seda(nums,target);


        return new int[]{min,max};
    }

    public static int sea(int[] nums, int target) {//最小
        int max=nums.length-1;
        int min=0;
        int mid;
        int x=0,d=0;
        do{
            mid=(min+max)>>1;
            if(target>nums[mid]){
                min=mid+1;
            }else if(target<nums[mid]){
                max=mid-1;
            }else{
                max=mid-1;
            }
        }while (max>=min);
        if(min>=nums.length||nums[min]!=target){
            min=-1;
        }

        return min;
    }

    public static int seda(int[] nums, int target) {
        int max=nums.length-1;
        int min=0;
        int mid;
        int x=0,d=0;
        do{
            mid=(min+max)>>1;
            if(target>nums[mid]){
                min=mid+1;
            }else if(target<nums[mid]){
                max=mid-1;
            }else{
                min=mid+1;
            }
        }while (max>=min);

        if(max<0||nums[max]!=target){
            max=-1;
        }
        return max;
    }
}
